//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "BlackCalculator.h"
using namespace Cephei::QL::Pricingengines;
#include <gen/QL/Instruments/StrikedTypePayoff.h>
using namespace Cephei::QL::Instruments;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (Cephei::QL::Instruments::IStrikedTypePayoff^ payoff, Double forward, Double stdDev, Microsoft::FSharp::Core::FSharpOption<Double>^ discount) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CStrikedTypePayoff^ _Cpayoff;
    try
    {
#ifdef HANDLE
        _phBlackCalculator = NULL;
#endif
        _Cpayoff = safe_cast<CStrikedTypePayoff^> (payoff);
        _Cpayoff->Lock();
        boost::shared_ptr<QuantLib::StrikedTypePayoff>& _payoff = static_cast<boost::shared_ptr<QuantLib::StrikedTypePayoff>&> (_Cpayoff->GetShared ()); 
        QuantLib::Real _forward = (QuantLib::Real)ValueHelper::Convert (forward); //d
        QuantLib::Real _stdDev = (QuantLib::Real)ValueHelper::Convert (stdDev); //d
        QuantLib::Real _discount = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (discount) ? (QuantLib::Real)ValueHelper::Convert (discount->Value) : 1.0); //4
        _ppBlackCalculator = new boost::shared_ptr<QuantLib::BlackCalculator> (new QuantLib::BlackCalculator ( _payoff,  _forward,  _stdDev,  _discount ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cpayoff != nullptr) _Cpayoff->Unlock();
    }
}
Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (QL::Option::TypeEnum optionType, Double strike, Double forward, Double stdDev, Microsoft::FSharp::Core::FSharpOption<Double>^ discount) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phBlackCalculator = NULL;
#endif
        QuantLib::Option::Type _optionType = (QuantLib::Option::Type)optionType ;
        QuantLib::Real _strike = (QuantLib::Real)ValueHelper::Convert (strike); //d
        QuantLib::Real _forward = (QuantLib::Real)ValueHelper::Convert (forward); //d
        QuantLib::Real _stdDev = (QuantLib::Real)ValueHelper::Convert (stdDev); //d
        QuantLib::Real _discount = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (discount) ? (QuantLib::Real)ValueHelper::Convert (discount->Value) : 1.0); //4
        _ppBlackCalculator = new boost::shared_ptr<QuantLib::BlackCalculator> (new QuantLib::BlackCalculator ( _optionType,  _strike,  _forward,  _stdDev,  _discount ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (boost::shared_ptr<QuantLib::BlackCalculator>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBlackCalculator = NULL;
#endif
	_ppBlackCalculator = &childNative;
    
}
Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (QuantLib::BlackCalculator& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phBlackCalculator = NULL;
#endif
	_ppBlackCalculator = new boost::shared_ptr<QuantLib::BlackCalculator> (&childNative);
    
    _BlackCalculatorOwner = owner;
    
}

Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (CBlackCalculator^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBlackCalculator = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppBlackCalculator = new boost::shared_ptr<QuantLib::BlackCalculator> (copy->GetShared());
        
    }
}
Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBlackCalculator = NULL;
#endif
	if (!t->IsSubclassOf(CBlackCalculator::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (QuantLib::Handle<QuantLib::BlackCalculator>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phBlackCalculator = &childNative;
	_ppBlackCalculator = &static_cast<boost::shared_ptr<QuantLib::BlackCalculator>>(childNative.currentLink());
    
    _BlackCalculatorOwner = owner;
}
Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (QuantLib::Handle<QuantLib::BlackCalculator> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phBlackCalculator = &childNative;
	_ppBlackCalculator = &static_cast<boost::shared_ptr<QuantLib::BlackCalculator>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Pricingengines::CBlackCalculator::CBlackCalculator (QuantLib::BlackCalculator childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phBlackCalculator = NULL;
#endif
	_ppBlackCalculator = new boost::shared_ptr<QuantLib::BlackCalculator> (new QuantLib::BlackCalculator (childNative));
    
}
#endif

Cephei::QL::Pricingengines::CBlackCalculator::~CBlackCalculator ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppBlackCalculator != NULL)
    {
	    delete _ppBlackCalculator;
        _ppBlackCalculator = NULL;
    }
}
Cephei::QL::Pricingengines::CBlackCalculator::!CBlackCalculator ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppBlackCalculator != NULL)
    {
	    delete _ppBlackCalculator;
    }
}
QuantLib::BlackCalculator& Cephei::QL::Pricingengines::CBlackCalculator::GetReference ()
{
    if (_ppBlackCalculator == NULL) throw REFNEW NativeNullException ();
	return **_ppBlackCalculator;
}
boost::shared_ptr<QuantLib::BlackCalculator>& Cephei::QL::Pricingengines::CBlackCalculator::GetShared ()
{
    if (_ppBlackCalculator == NULL) throw REFNEW NativeNullException ();
	return *_ppBlackCalculator;
}
QuantLib::BlackCalculator* Cephei::QL::Pricingengines::CBlackCalculator::GetPointer ()
{
    if (_ppBlackCalculator == NULL) throw REFNEW NativeNullException ();
	return &**_ppBlackCalculator;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::BlackCalculator>& Cephei::QL::Pricingengines::CBlackCalculator::GetHandle ()
{
	if (_phBlackCalculator == NULL)
	{
		_phBlackCalculator = new Handle<QuantLib::BlackCalculator> (*_ppBlackCalculator);
	}
	return *_phBlackCalculator;
}
#endif
bool Cephei::QL::Pricingengines::CBlackCalculator::HasNative () 
{
	return (_ppBlackCalculator != NULL);
}

Double Cephei::QL::Pricingengines::CBlackCalculator::Alpha::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->alpha ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::Beta::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->beta ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::Delta (Double spot)
{
    try
    {
        QuantLib::Real _spot = (QuantLib::Real)ValueHelper::Convert (spot); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->delta ( _spot );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::DeltaForward::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->deltaForward ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::DividendRho (Double maturity)
{
    try
    {
        QuantLib::Time _maturity = (QuantLib::Time)ValueHelper::Convert (maturity); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->dividendRho ( _maturity );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::Elasticity (Double spot)
{
    try
    {
        QuantLib::Real _spot = (QuantLib::Real)ValueHelper::Convert (spot); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->elasticity ( _spot );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::ElasticityForward::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->elasticityForward ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::Gamma (Double spot)
{
    try
    {
        QuantLib::Real _spot = (QuantLib::Real)ValueHelper::Convert (spot); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->gamma ( _spot );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::GammaForward::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->gammaForward ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::ItmAssetProbability::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->itmAssetProbability ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::ItmCashProbability::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->itmCashProbability ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::Rho (Double maturity)
{
    try
    {
        QuantLib::Time _maturity = (QuantLib::Time)ValueHelper::Convert (maturity); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->rho ( _maturity );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::StrikeSensitivity::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->strikeSensitivity ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::Theta (Double spot, Double maturity)
{
    try
    {
        QuantLib::Real _spot = (QuantLib::Real)ValueHelper::Convert (spot); //a
        QuantLib::Time _maturity = (QuantLib::Time)ValueHelper::Convert (maturity); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->theta ( _spot,  _maturity );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::ThetaPerDay (Double spot, Double maturity)
{
    try
    {
        QuantLib::Real _spot = (QuantLib::Real)ValueHelper::Convert (spot); //a
        QuantLib::Time _maturity = (QuantLib::Time)ValueHelper::Convert (maturity); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->thetaPerDay ( _spot,  _maturity );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::Value::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->value ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Pricingengines::CBlackCalculator::Vega (Double maturity)
{
    try
    {
        QuantLib::Time _maturity = (QuantLib::Time)ValueHelper::Convert (maturity); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBlackCalculator)->vega ( _maturity );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Pricingengines::IBlackCalculator^ Cephei::QL::Pricingengines::CBlackCalculator_Factory::Create (Cephei::QL::Instruments::IStrikedTypePayoff^ payoff, Double forward, Double stdDev, Microsoft::FSharp::Core::FSharpOption<Double>^ discount)
{
    return REFNEW CBlackCalculator ( payoff,  forward,  stdDev,  discount);
}
Cephei::QL::Pricingengines::IBlackCalculator^ Cephei::QL::Pricingengines::CBlackCalculator_Factory::Create (QL::Option::TypeEnum optionType, Double strike, Double forward, Double stdDev, Microsoft::FSharp::Core::FSharpOption<Double>^ discount)
{
    return REFNEW CBlackCalculator ( optionType,  strike,  forward,  stdDev,  discount);
}
